package ua.vn.ticket_scanner.nfc;

import android.content.Intent;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.MifareClassic;

/**
 * Created by Ivan on 14.06.13.
 */
public class NFCEventHelper {

    public static boolean isIntentNFC(Intent intent) {
        return isIntentNFCNdef(intent) ||
                isIntentNFCTech(intent) ||
                isIntentNFCTag(intent);
    }

    public static boolean isIntentNFCNdef(Intent intent) {
        String action = intent.getAction();
        return NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action);
    }

    public static boolean isIntentNFCTech(Intent intent) {
        String action = intent.getAction();
        return NfcAdapter.ACTION_TECH_DISCOVERED.equals(action);
    }

    public static boolean isIntentNFCTag(Intent intent) {
        String action = intent.getAction();
        return NfcAdapter.ACTION_TAG_DISCOVERED.equals(action);
    }

    public static boolean isIntentMifareClassic(Intent intent) {
        Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        MifareClassic mifareTag = MifareClassic.get(tag);
        return mifareTag != null;
    }
}
